home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Loadstar 164
/
164.d81
/
b.solve myschess
(
.txt
)
< prev
next >
Wrap
Commodore BASIC
|
2022-08-26
|
11KB
|
299 lines
5 dv=peek(186):ifdv<8thendv=8
8 poke53371,0
10 dimm%(5,5,27)
20 dime(5),e$(5),f(8),h(5)
30 dims(88),s1%(120,5),s2%(120,88),t%(120)
40 dimg%(50,2),g$(50)
50 k$="[150] [144] [150] [144] [150] [144] [150] [144] [146]":l$="[144] [150] [144] [150] [144] [150] [144] [150] [144][146]"
60 m$="[150] [144] [150] [144] [150] [144] [150] [144] [146]":n$="[144] [150] [144] [150] [144] [150] [144] [150] [144][146]"
70 gosub1510:fori=1to5:readh(i):next
80 print"-[199]enerating matrix of moves."
90 fori=1to5:m%(1,i,0)=0
100 ife(i)-10*int(e(i)/10+.01)<3ore(i)>78then120
110 m%(1,i,0)=m%(1,i,0)+1:m%(1,i,m%(1,i,0))=e(i)+8
120 ife(i)-10*int(e(i)/10+.01)=1ore(i)>68then140
130 m%(1,i,0)=m%(1,i,0)+1:m%(1,i,m%(1,i,0))=e(i)+19
140 ife(i)-10*int(e(i)/10+.01)=8ore(i)>67then160
150 m%(1,i,0)=m%(1,i,0)+1:m%(1,i,m%(1,i,0))=e(i)+21
160 ife(i)-10*int(e(i)/10+.01)>6ore(i)>76then180
170 m%(1,i,0)=m%(1,i,0)+1:m%(1,i,m%(1,i,0))=e(i)+12
180 ife(i)-10*int(e(i)/10+.01)>6ore(i)<21then200
190 m%(1,i,0)=m%(1,i,0)+1:m%(1,i,m%(1,i,0))=e(i)-8
200 ife(i)-10*int(e(i)/10+.01)=8ore(i)<31then220
210 m%(1,i,0)=m%(1,i,0)+1:m%(1,i,m%(1,i,0))=e(i)-19
220 ife(i)-10*int(e(i)/10+.01)=1ore(i)<32then240
230 m%(1,i,0)=m%(1,i,0)+1:m%(1,i,m%(1,i,0))=e(i)-21
240 ife(i)-10*int(e(i)/10+.01)<3ore(i)<23then260
250 m%(1,i,0)=m%(1,i,0)+1:m%(1,i,m%(1,i,0))=e(i)-12
260 next
270 fori=1to5:m%(2,i,0)=0
280 l1=e(i)-10*int(e(i)/10+.01):l2=int(e(i)/10+.01):ifl1=1orl2=8then310
290 l3=l1-1:if8-l2<l3thenl3=8-l2
300 forj=1tol3:m%(2,i,0)=m%(2,i,0)+1:m%(2,i,m%(2,i,0))=e(i)+9*j:next
310 l1=e(i)-10*int(e(i)/10+.01):l2=int(e(i)/10+.01):ifl1=8orl2=8then340
320 l3=8-l1:if8-l2<l3thenl3=8-l2
330 forj=1tol3:m%(2,i,0)=m%(2,i,0)+1:m%(2,i,m%(2,i,0))=e(i)+11*j:next
340 l1=e(i)-10*int(e(i)/10+.01):l2=int(e(i)/10+.01):ifl1=8orl2=1then370
350 l3=8-l1:ifl2-1<l3thenl3=l2-1
360 forj=1tol3:m%(2,i,0)=m%(2,i,0)+1:m%(2,i,m%(2,i,0))=e(i)-9*j:next
370 l1=e(i)-10*int(e(i)/10+.01):l2=int(e(i)/10+.01):ifl1=1orl2=1then400
380 l3=l1-1:ifl2-1<l3thenl3=l2-1
390 forj=1tol3:m%(2,i,0)=m%(2,i,0)+1:m%(2,i,m%(2,i,0))=e(i)-11*j:next
400 next
410 fori=1to5:m%(3,i,0)=0
420 l2=int(e(i)/10+.01):ifl2=8then440
430 forj=1to8-l2:m%(3,i,0)=m%(3,i,0)+1:m%(3,i,m%(3,i,0))=e(i)+10*j:next
440 l1=e(i)-10*int(e(i)/10+.01):ifl1=8then460
450 forj=1to8-l1:m%(3,i,0)=m%(3,i,0)+1:m%(3,i,m%(3,i,0))=e(i)+j:next
460 l2=int(e(i)/10+.01):ifl2=1then480
470 forj=1tol2-1:m%(3,i,0)=m%(3,i,0)+1:m%(3,i,m%(3,i,0))=e(i)-10*j:next
480 l1=e(i)-10*int(e(i)/10+.01):ifl1=1then500
490 forj=1tol1-1:m%(3,i,0)=m%(3,i,0)+1:m%(3,i,m%(3,i,0))=e(i)-j:next
500 next
510 fori=1to5:m%(4,i,0)=m%(2,i,0)+m%(3,i,0)
520 forj=1tom%(2,i,0):m%(4,i,j)=m%(2,i,j):next
530 forj=1tom%(3,i,0):m%(4,i,m%(2,i,0)+j)=m%(3,i,j):next
540 next
550 fori=1to5:m%(5,i,0)=0
560 l1=e(i)-10*int(e(i)/10+.01):l2=int(e(i)/10+.01):ifl1=1orl2=8then580
570 m%(5,i,0)=m%(5,i,0)+1:m%(5,i,m%(5,i,0))=e(i)+9
580 l1=e(i)-10*int(e(i)/10+.01):l2=int(e(i)/10+.01):ifl1=8orl2=8then600
590 m%(5,i,0)=m%(5,i,0)+1:m%(5,i,m%(5,i,0))=e(i)+11
600 l1=e(i)-10*int(e(i)/10+.01):l2=int(e(i)/10+.01):ifl1=8orl2=1then620
610 m%(5,i,0)=m%(5,i,0)+1:m%(5,i,m%(5,i,0))=e(i)-9
620 l1=e(i)-10*int(e(i)/10+.01):l2=int(e(i)/10+.01):ifl1=1orl2=1then640
630 m%(5,i,0)=m%(5,i,0)+1:m%(5,i,m%(5,i,0))=e(i)-11
640 l2=int(e(i)/10+.01):ifl2=8then660
650 m%(5,i,0)=m%(5,i,0)+1:m%(5,i,m%(5,i,0))=e(i)+10
660 l1=e(i)-10*int(e(i)/10+.01):ifl1=8then680
670 m%(5,i,0)=m%(5,i,0)+1:m%(5,i,m%(5,i,0))=e(i)+1
680 l2=int(e(i)/10+.01):ifl2=1then700
690 m%(5,i,0)=m%(5,i,0)+1:m%(5,i,m%(5,i,0))=e(i)-10
700 l1=e(i)-10*int(e(i)/10+.01):ifl1=1then720
710 m%(5,i,0)=m%(5,i,0)+1:m%(5,i,m%(5,i,0))=e(i)-1
720 next
730 print"[145]-[199]enerating matrix of permutations."
740 s1%(0,0)=0:forl5=1to5
750 forl4=1to5:ifl4=l5then850
760 forl3=1to5:ifl3=l4orl3=l5then840
770 forl2=1to5:ifl2=l3orl2=l4orl2=l5then830
780 l1=15-l5-l4-l3-l2
790 s1%(0,0)=s1%(0,0)+1
800 f(1)=l1:f(2)=l2:f(3)=l3:f(4)=l4:f(5)=l5
810 fori=1to5:forj=1to5:iff(j)=ithens1%(s1%(0,0),i)=j:j=5
820 next:next
830 nextl2
840 nextl3
850 nextl4
860 nextl5
870 print"[145]-[199]enerating matrix of combined hits."
880 fori=1to120
890 forj=1to5
900 fork=1tom%(j,s1%(i,j),0)
910 s2%(i,m%(j,s1%(i,j),k))=s2%(i,m%(j,s1%(i,j),k))+1
920 next:next:next
930 print"[145]-[199]enerating table of legal boards. ":f(6)=0:f(7)=0:f(8)=0
940 ifg%(0,1)=0thent%(0)=120:fori=1to120:t%(i)=i:next:f(6)=120:f(7)=120:goto1010
950 fori=1tot%(0)
960 ifs2%(t%(i),g%(g%(0,1),1))<>g%(g%(0,1),2)then980
970 f(6)=f(6)+1:t%(f(6))=t%(i):f(8)=f(7):f(7)=t%(i)
980 next:t%(0)=f(6)
990 ift%(0)=0then2640
1000 ift%(0)=1then1420
1010 print"[145]-[199]enerating matrix to compare squares."
1020 fori=11to88:s(i)=0:next
1030 fori=11to81step10:forj=0to7:fork=0to5:f(k)=0:next
1040 fork=1tot%(0):f(s2%(t%(k),i+j))=f(s2%(t%(k),i+j))+1:next
1050 fork=0to5:s(i+j)=s(i+j)+abs(f(k)-t%(0)/6):next
1060 nextj,i
1070 if se=1 then1270
1080 fori=1to5:s(e(i))=500:next
1090 if t%(0)>2 then1270
1100 fl=0:fori=11to81step10:forj=0to7
1110 if s2%(f(7),i+j)=s2%(f(8),i+j) then1150
1120 fork=1to5:ife(k)=i+j thenk=9
1130 next:if k>9 then1150
1140 fl=1:j=7:i=81
1150 nextj,i:if fl=1 then1270
1160 print"[147][199]uessing at complete arrangement:"
1170 print"[211]quare ?s:";g%(0,1);" [208]osition ?s: 1":gosub2500
1180 print" [203]night on ";e$(s1%(f(8),1));","
1190 print" [194]ishop on ";e$(s1%(f(8),2));","
1200 print" [210]ook on ";e$(s1%(f(8),3));","
1210 print" [209]ueen on ";e$(s1%(f(8),4));", and"
1220 print" [203]ing on ";e$(s1%(f(8),5));".":print
1230 print"[201]s this right (y/n)? ";:poke198,0
1240 geta$:if ((a$<>"y") and (a$<>"n")) then goto1240
1250 if (a$="y") then print"[217]es.":goto1500
1260 g%(0,1)=g%(0,1)+1:g%(g%(0,1),1)=f(8)+1000:print"[206]o.":goto1420
1270 print"[145]-[211]electing best scoring square. "
1280 if (g%(0,1)<1) then goto1300
1290 fori=1tog%(0,1):s(g%(i,1))=999:next
1300 g%(0,1)=g%(0,1)+1:g%(g%(0,1),1)=11
1310 fori=11to81step10:forj=0to7
1320 if (s(i+j)<s(g%(g%(0,1),1))) then g%(g%(0,1),1)=i+j
1330 nextj,i
1340 print"[147]";t%(0);"permutations are possible.":print
1350 print"[199]uess";g%(0,1);"is square ";
1360 a$=str$(g%(g%(0,1),1)):b$=chr$((asc(right$(a$,1)))+16):printb$;
1370 c$=chr$(asc(right$(left$(a$,2),1))):printc$;".":g$(g%(0,1))=b$+c$
1380 gosub2420
1390 print"[200]ow many men attack this square?";:poke198,0
1400 geta$:if ((a$<"0") or (a$>"5")) then goto1400
1410 g%(g%(0,1),2)=val(a$):printval(a$):print:goto930
1420 print"[147][211]olution found after";g%(0,1);"guess";
1430 ifg%(0,1)<>1thenprint"es";
1440 print".":gosub2570
1450 print"[203]night on square ";e$(s1%(f(7),1));","
1460 print"[194]ishop on square ";e$(s1%(f(7),2));","
1470 print"[210]ook on square ";e$(s1%(f(7),3));","
1480 print"[209]ueen on square ";e$(s1%(f(7),4));", and"
1490 print"[203]ing on square ";e$(s1%(f(7),5));"."
1500 goto2740
1510 poke53280,13:poke53281,13:print"[147]";chr$(14);"[144] [212]o [211]olve [205]ystery [211]quare [195]hess":print
1520 printtab(7);"[208]rogrammed by [198]loyd [203]irk":print
1530 print" [212]his program is to solve the problem"
1540 print"generated by the [205]ystery [211]quare [195]hess"
1550 print"program or by a person. [198]ive squares"
1560 print"are chosen on a chessboard and their"
1570 print"coordinates given to this program. [212]he"
1580 print"program will place a [203]night, [194]ishop,"
1590 print"[210]ook, [209]ueen, and [203]ing on the five"
1600 print"mystery squares by asking only 2 types"
1610 print"of questions:"
1620 print" 1. [215]hen the pieces are properly set up,";
1630 print" how many attack [212][200][201][211] square?"
1640 print" 2. [201]s this the correct position?"
1650 print" [193]s the piece names suggest, these have";
1660 print"the attacking abilities of their chess"
1670 print"counterparts, except that they can"
1680 print"attack [212][200][210][207][213][199][200] any other piece. [197]ach"
1690 print"man attacks as though it is the only"
1700 print"man on the board."
1710 printtab(5);"<-[208]ress space-bar for more.->":poke198,0
1712 fori=217to242:pokei,peek(i)or128:next
1720 geta$:ifa$=""then1720
1730 print"[147] [212]he [193]ttack [208]atterns of the [208]ieces":print
1740 print"[206] = [203]night [194] = [194]is